<template>
	<view class="container">
		<view class="tabs" @touchmove.stop="false">
			<view class="tab" :class="{ active: currentTab === index }" v-for="(tab, index) in tabs" :key="index" @tap="switchTab(index)">{{ tab.name }}</view>
		</view>
		<view class="waterfall">
			<view class="card" v-for="(item, index) in 30" :key="index">
				<image src="https://th.bing.com/th/id/OIP.QOXdL5ua9SGxEZc9ojZPHgHaEe?cb=iwp2&rs=1&pid=ImgDetMain" class="card-img" mode="aspectFill" />
				<view class="card-title">杭州40℃的高温，不来一个清热</view>
				<view class="card-footer">
					<view class="user-info">
						<image src="https://th.bing.com/th/id/OIP.QOXdL5ua9SGxEZc9ojZPHgHaEe?cb=iwp2&rs=1&pid=ImgDetMain" class="user-avatar" />
						<text class="user-name">用户名</text>
					</view>
					<view class="card-actions">
						<uni-icons type="hand-up-filled" size="25" v-if="index > 1" color="#D8D8D8"></uni-icons>
						<uni-icons type="hand-up-filled" size="25" v-else color="#ff4a4d"></uni-icons>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				cards: [],
				currentTab: 0,
				tabs: [
					{ name: '推荐' },
					{ name: '穿搭' },
					{ name: '运动打卡' },
					{ name: '图文分享' },
					{ name: '视频' },
					{ name: '视频' },
					{ name: '视频' },
					{ name: '视频' },
					{ name: '视频' }
				]
			}
		},
		methods: {
			switchTab(index) {
				this.currentTab = index;
				// 这里可以根据不同的标签加载不同的数据
				this.loadTabData(index);
			},
			loadTabData(index) {
				// TODO: 根据标签加载对应的数据
				console.log('加载标签数据:', this.tabs[index].name);
			}
		},
		onShow() {
			// 每个tab页都要更新一下角标数量
			this.$badge.refreshFriendBadge();
			this.$badge.refreshChatBadge();
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		background: #f7f7f7;
		height: 100%;
		overflow: auto;
	}

	.tabs {
		background: #fff;
		border-bottom: 1px solid #eee;
		height: 72rpx;
		line-height: 72rpx;
		align-items: center;
		padding: 0 40rpx;
		overflow: auto;
		white-space: nowrap;
		// position: fixed;
		// top: 0;

		.tab {
			display: inline-block;
			text-align: center;
			color: #888;
			padding-right: 20px;

			&.active {
				color: #333;
			}
		}
	}

	.waterfall {
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
		padding: 20rpx;
	}

	.card {
		width: 48%;
		background: #fff;
		border-radius: 16rpx;
		margin-bottom: 20rpx;
		overflow: hidden;
		box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);

		.card-img {
			width: 100%;
			height: 400rpx;
			object-fit: cover;
			display: block;
		}

		.card-title {
			font-size: 28rpx;
			font-weight: bold;
			margin: 16rpx 12rpx 0 12rpx;
			color: #000000;
		}

		.card-footer {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 12rpx;

			.user-info {
				display: flex;
				align-items: center;

				.user-avatar {
					width: 36rpx;
					height: 36rpx;
					border-radius: 50%;
					margin-right: 8rpx;
				}

				.user-name {
					font-size: 28rpx;
					color: #909090;
					line-height: 40rpx;
				}
			}

			.card-actions {
				.iconfont {
					font-size: 28rpx;
					color: #ccc;
					margin-left: 16rpx;
				}
			}
		}
	}
</style>